var info = {
    vueInfo: null,
    URL: {
        getUserInfoUrl: "/api/userInfo/getUserInfo",
        saveUserInfoUrl: "/api/userInfo/saveUserInfo",
    },
    detail: {
        getUserInfo: function () {
            $.post(info.URL.getUserInfoUrl, {}, function (data) {
                if (!data.hasError) {
                    info.vueInfo = new Vue({
                        el: "#all",
                        data: {
                            userInfo: data.object,
                            sex: data.object.sex == null ? 1 : data.object.sex,
                            credentialType: data.object.credentialType == null ? "身份证" : data.object.credentialType,
                            aboardPoint: data.object.aboardPoint == null ? "" : data.object.aboardPoint,
                            isSingle: data.object.isSingle == null ? "" : data.object.isSingle,

                        },
                        mounted: function () {
                            winInit();
                            $.pop.load(false, null);
                        },
                        methods: {
                            saveInfo: function () {
                                var vmObj = this;
                                info.detail.saveUserInfo(vmObj);
                            }
                        },
                        filters: {
                            regFlagNext: function (value) {
                                if (__JsUtil.isNullOrEmpty(value) || value == 0) {
                                    return "下一步";
                                } else {
                                    return "保存";
                                }
                            },
                            levelStr: function (value) {
                                if (value == 1) {
                                    return "普通 580";
                                } else if (value == 2) {
                                    return "普通 880";
                                } else if (value == 3) {
                                    return "VIP 1380";
                                } else if (value == 4) {
                                    return "VIP 1680";
                                }
                            },
                            remarkStr:function (value) {
                                if (value >= 3){
                                    return "单间补差价480，现场酒店支付";
                                }else{
                                    return "单间补差价300，现场酒店支付";
                                }
                            }
                        }
                    });
                } else {
                    if (data.errType != null) {
                        $.pop.tips(data.error);
                        if (data.errType == "NOSESSION") {
                            setTimeout(function () {
                                window.location.href = data.errUrl;
                                return false;
                            }, 400);
                        }
                    }
                }
            }, "json").error(function (XMLHttpRequest, textStatus, errorThrown) {
                $.pop.load(false, null);
                $.pop.tips("系统繁忙，请稍后" + XMLHttpRequest.status + "," + XMLHttpRequest.readyState + "," + textStatus);
            });
        },
        saveUserInfo: function (vmObj) {
            var name = vmObj.userInfo.name;
            if (__JsUtil.isNullOrEmpty(name)) {
                $.pop.tips("请输入姓名");
                return false;
            }
            var ticketNo = vmObj.userInfo.ticketNo;
            if (__JsUtil.isNullOrEmpty(ticketNo)) {
                $.pop.tips("请输入券号");
                return false;
            }
            var sex = vmObj.sex;
            if (__JsUtil.isNullOrEmpty(sex)) {
                $.pop.tips("请输入性别");
                return false;
            }
            var mobile = vmObj.userInfo.mobile;
            if (!__DataVail.isMobile(mobile)) {
                $.pop.tips("请输入正确的手机号");
                return false;
            }
            var company = vmObj.userInfo.company;
            if (__JsUtil.isNullOrEmpty(company)) {
                $.pop.tips("请输入公司");
                return false;
            } else {
                if (company.length < 4) {
                    $.pop.tips("请输入公司");
                    return false;
                }
            }
            var position = vmObj.userInfo.position;
            if (__JsUtil.isNullOrEmpty(position)) {
                $.pop.tips("请输入职位");
                return false;
            }
            var credentialNo = vmObj.userInfo.credentialNo;
            if (__JsUtil.isNullOrEmpty(credentialNo)) {
                $.pop.tips("请输入证件号");
                return false;
            } else {
                if (vmObj.credentialType == "身份证") {
                    if (!__DataVail.idCard(credentialNo)) {
                        $.pop.tips("请输入正确身份证");
                        return false;
                    }
                }
            }
            var email = vmObj.userInfo.email;
            if (!__DataVail.isEmail(email)) {
                $.pop.tips("请输入正确的邮箱");
                return false;
            }
            if (vmObj.userInfo.level != 1) {
                var aboardPoint = vmObj.aboardPoint;
                if (__JsUtil.isNullOrEmpty(aboardPoint)) {
                    $.pop.tips("请选择上车点");
                    return false;
                }
                var isSingle = vmObj.isSingle;
                if (__JsUtil.isNullOrEmpty(isSingle)) {
                    $.pop.tips("请选择是否单间");
                    return false;
                }
            }
            $.pop.load(true, "正在保存...");
            $.post(info.URL.saveUserInfoUrl, $("#myForm").serialize(), function (data) {
                if (!data.hasError) {
                    if (__JsUtil.isNullOrEmpty(vmObj.userInfo.regFlag) || vmObj.userInfo.regFlag == 0) {
                        window.location.href = 'forum.html';
                    } else {
                        window.location.href = 'index.html';
                    }
                    $.pop.load(false, null);
                } else {
                    $.pop.tips(data.error);
                    if (data.errType != null) {
                        if (data.errType == "NOSESSION") {
                            setTimeout(function () {
                                window.location.href = data.errUrl;
                                return false;
                            }, 400);
                        }
                    }
                }
            }, "json").error(function (XMLHttpRequest, textStatus, errorThrown) {
                $.pop.load(false, null);
                $.pop.tips("系统繁忙，请稍后" + XMLHttpRequest.status + "," + XMLHttpRequest.readyState + "," + textStatus);
            });
        }
    }
}